package ai.people.netmon.framework.domain.gang.construction.entity;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.serializer.ToStringSerializer;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 关系库-规则
 * </p>
 *
 * @author zhenglin
 * @since 2022-07-19
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName(schema = "webservice")
@NoArgsConstructor
public class RelationRule implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 主键ID
     */
    @JSONField(serializeUsing = ToStringSerializer.class)
    private Long id;

    /**
     * 规则名
     */
    private String ruleName;

    /**
     * 规则字段
     */
    private String ruleFields;

    /**
     * 扩线关系点value
     */
    private String expListValue;
    /**
     * 类型value
     */
    private String expTypeValue;

    public List<Rule> buildRule() {
        if (StringUtils.isNotBlank(ruleFields)) {
            return JSONArray.parseArray(ruleFields, Rule.class);

        }
        return null;
    }


    @Data
    public static class Rule {
        /**
         * 代码
         */
        private String code;
        /**
         * 名字
         */
        private String name;
        /**
         * left num
         */
        @Min(value = 0, message = "left num must be greater than {value}")
        @Max(value = 100, message = "left num must be less than {value}")
        private Integer lNum;
        /**
         * right num
         */
        private Integer rNum;
        /**
         * 符号
         */
        private String symbol;
        /**
         * 下一个符号
         */
        private String nextSymbol;
    }
}
